<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= title %></title>
    <link rel="stylesheet" href="/stylesheets/style.css">
</head>
<body>
    <div class="container">
        <header>
            <h1><%= title %></h1>
        </header>

        <main>
            <div class="form-container">

                <div class="actions">
                    <a href="/student/list" class="btn btn-secondary">返回学生列表</a>
                </div>


                <% if (errors && errors.general) { %>
                    <div class="alert alert-error">
                        <%= errors.general %>
                    </div>
                <% } %>

                <form action="/student/update" method="POST" class="student-form">
                    <input type="hidden" name="id" value="<%= student.id %>">
                    
                    <div class="form-group">
                        <label for="name">姓名 <span class="required">*</span></label>
                        <input type="text" 
                               id="name" 
                               name="name" 
                               value="<%= student.name || '' %>"
                               class="<%= errors.name ? 'error' : '' %>"
                               required>
                        <% if (errors.name) { %>
                            <span class="error-message"><%= errors.name %></span>
                        <% } %>
                    </div>

                    <div class="form-group">
                        <label for="age">年龄 <span class="required">*</span></label>
                        <input type="number" 
                               id="age" 
                               name="age" 
                               value="<%= student.age || '' %>"
                               min="1" 
                               max="150"
                               class="<%= errors.age ? 'error' : '' %>"
                               required>
                        <% if (errors.age) { %>
                            <span class="error-message"><%= errors.age %></span>
                        <% } %>
                    </div>

                    <div class="form-group">
                        <label for="gender">性别 <span class="required">*</span></label>
                        <select id="gender" 
                                name="gender" 
                                class="<%= errors.gender ? 'error' : '' %>"
                                required>
                            <option value="">请选择性别</option>
                            <option value="男" <%= student.gender === '男' ? 'selected' : '' %>>男</option>
                            <option value="女" <%= student.gender === '女' ? 'selected' : '' %>>女</option>
                        </select>
                        <% if (errors.gender) { %>
                            <span class="error-message"><%= errors.gender %></span>
                        <% } %>
                    </div>

                    <div class="form-group">
                        <label for="major">专业 <span class="required">*</span></label>
                        <input type="text" 
                               id="major" 
                               name="major" 
                               value="<%= student.major || '' %>"
                               class="<%= errors.major ? 'error' : '' %>"
                               required>
                        <% if (errors.major) { %>
                            <span class="error-message"><%= errors.major %></span>
                        <% } %>
                    </div>

                    <div class="form-group">
                        <label for="score">成绩 <span class="required">*</span></label>
                        <input type="number" 
                               id="score" 
                               name="score" 
                               value="<%= student.score || '' %>"
                               min="0" 
                               max="100" 
                               step="0.01"
                               class="<%= errors.score ? 'error' : '' %>"
                               required>
                        <% if (errors.score) { %>
                            <span class="error-message"><%= errors.score %></span>
                        <% } %>
                    </div>

                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">更新学生信息</button>
                        <a href="/student/list" class="btn btn-secondary">取消</a>
                    </div>
                </form>
            </div>
        </main>

        <footer>
            <p>&copy; 2025 学生信息管理系统(小何技术支持)</p>
        </footer>
    </div>
</body>
</html>
